
"""
    守护线程：在程序中将子线程设置为守护线程，则该子线程会在主线程结束时自动退出
        thread.setDaemon(True)
"""
import time
import threading


def work():
    for i in range(10):
        print("work...")
        time.sleep(0.5)


if __name__ == '__main__':
    thread1 = threading.Thread(target=work)

    # 子线程守护主线程，主线程结束子线程也结束
    thread1.setDaemon(True)

    thread1.start()

    time.sleep(2)
    print("main线程结束")
    exit()

